package com.aihuishou.monitor;

import com.aihuishou.monitor.model.DefaultEvent;
import com.aihuishou.monitor.model.DefaultTransaction;

/**
 * 埋点工具类，待完善
 */
public class LogMonitor {
    private LogMonitor() {
    }

    public static DefaultTransaction newTransaction(String type, String name) {
        DefaultTransaction t = new DefaultTransaction();
        t.setType(type);
        t.setName(name);
        try {
            MessageThreadLocal.Context context = MessageThreadLocal.getContext();
            context.addMessage(t);
        } catch (Exception ignored) {
        }
        return t;
    }

    public static void logEvent(String type, String name) {
        logEvent(type, name, null, LogConstants.SUCCESS);
    }

    public static void logEvent(String type, String name, String attr) {
        logEvent(type, name, attr, LogConstants.SUCCESS);
    }

    public static void logEvent(String type, String name, String attr, String status) {
        DefaultEvent event = new DefaultEvent();
        event.setType(type);
        event.setName(name);
        event.setAttribute(attr);
        event.setStatus(status);
        event.complete();
        // 提交event
        MessageThreadLocal.getContext().addMessage(event);
        MessageThreadLocal.getContext().endMessage(event);
    }

}
